import { axiosMock, delayFn, randArrItem } from '@/services/axiosMock'
import { IListItem } from './interface'
import { reqToList } from './utils'

axiosMock('default', mock => {
  // 获取运单信息列表
  mock.onPost(`/tmsapi/track_waybill/listWaybillInfo`).reply(
    delayFn(600, ({ data }) => {
      const d = data as { waybillNos?: string[]; fbaIds?: string[] }
      return {
        success: true,
        data: reqToList(d)
          .filter(() => randArrItem([true], 0.3))
          .map(({ type, value }, index) => {
            return {
              logisticsStatusEn: randArrItem([
                'Handling',
                'Exporting',
                'In Transit',
                'Importing',
                'Transporting',
                'Out For Delivery',
                'Delivered',
              ]),
              waybillNo: randArrItem([type === 'waybillNos' ? value : `LH01390125${index}`]),
              fbaId: randArrItem([type === 'fbaIds' ? value : randArrItem([`R720938${index}`], 0.1)]),
              age: randArrItem(['1', '2', '3'], 0.1),
              deliveryDate: randArrItem([`2024-12-11`, `2025-12-11`], 0.1),
              latestRoute: randArrItem(
                [
                  '【Port of Loading】LH01410015 has been transported by trailer, and upon arrival at the port, Chavez Theresa waits, F7987987, arrives at ABE1 and prepares for AAA departure',
                  '【Port of Diarge】LH01410015 has been transported by trailer, and upon arrival at the port, Chavez Theresa waits, F7987987',
                  '【Port of Discharge】LH01410015 has been transported by trailer, and upon arrival at the port',
                ],
                0.1,
              ),
              markFlag: randArrItem([0, 0, 0, 1], 0.1),
            } satisfies Omit<IListItem, '$key'>
          }),
      }
    }),
  )
})
